home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Animation How-To
/
Animation How-to CD.iso
/
PLY
/
CHAPTER4
/
THREAD
/
BEZIER.BAS
next >
Wrap
BASIC Source File
|
1994-01-01
|
3KB
|
109 lines
' BEZIER.BAS
DECLARE SUB rotate (x, y, z)
COMMON SHARED rad, xrotate, yrotate, zrotate
TYPE Vector
x AS SINGLE
y AS SINGLE
z AS SINGLE
END TYPE
DIM p(4) AS Vector
pi = 3.1415927#
rad = pi / 180
SCREEN 12
WINDOW (-16, -4)-(16, 20)
CLS
' our four control points. These get spiraled
' down a coil to generate the bezier batches
p(1).x = 1: p(1).y = 1: p(1).z = 0
p(2).x = -1: p(2).y = 1: p(2).z = 0
p(3).x = 1: p(3).y = -1: p(3).z = 0
p(4).x = -1: p(4).y = -1: p(4).z = 0
' show a spiral path 2-D
FOR a = 90 TO 90 + 360 * 3
y = 10 * SIN(a * rad)
CIRCLE (y, (a / 75) - 1), .1, 1
PAINT (y, (a / 75) - 1), 15, 1
NEXT a
FOR dat = 0 TO 44 '45 frames
xrotate = 0
yrotate = 0
zrotate = 4
'take 4 points in a square and rotate them
FOR a = 1 TO 4
CALL rotate(p(a).x, p(a).y, p(a).z)
NEXT a
r = 10
ang = 0 ' initial value for ang = 0
thread = 5 / 360 ' gives 5 units up per 360 degrees
LOCATE 1, 1: PRINT "Frame "; dat
FOR patch = 1 TO 24 ' 24 patches spanning 45 degrees each
FOR n = 1 TO 4 ' 4 sets of 4 points per patch
FOR a = 1 TO 4 ' each point
xrotate = 0
yrotate = ang ' rotate about y axis
zrotate = 0
tx = p(a).x + r ' offset sets a circle
ty = p(a).y + ang * thread ' this gives a spiral
tz = p(a).z + 0
CALL rotate(tx, ty, tz)
IF n = 2 OR n = 3 THEN
tx = tx * 1.04 ' move the middle two control point sets
tz = tz * 1.04 ' out to make the spiral rounder
END IF
CIRCLE (tx, ty), .1, a + k
NEXT a
' ang isn't indexed after the last set,
' so the bezier ends will overlap
IF n < 4 THEN ang = ang + (45 / 3)
NEXT n
NEXT patch
NEXT dat
SUB rotate (x, y, z)
'rotate
x0 = x
y0 = y
z0 = z
x1 = x0
y1 = y0 * COS(xrotate * rad) - z0 * SIN(xrotate * rad)
z1 = y0 * SIN(xrotate * rad) + z0 * COS(xrotate * rad)
x2 = z1 * SIN(yrotate * rad) + x1 * COS(yrotate * rad)
y2 = y1
z2 = z1 * COS(yrotate * rad) - x1 * SIN(yrotate * rad)
x3 = x2 * COS(zrotate * rad) - y2 * SIN(zrotate * rad)
y3 = x2 * SIN(zrotate * rad) + y2 * COS(zrotate * rad)
z3 = z2
x = x3
y = y3
z = z3
END SUB